package com.hbzhit.modules.sys.controller;

import com.alibaba.fastjson.JSONObject;
import com.hbzhit.common.utils.ConfigConstant;
import com.hbzhit.common.utils.R;
import com.hbzhit.common.validator.ValidatorUtils;
import com.hbzhit.modules.sys.entity.SysLogoEntity;
import com.hbzhit.modules.sys.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * LOGO配置
 *
 * @author DING
 * @date 2019-07-09 19:07:15
 */
@Api(tags = {"LOGO配置"})
@RestController
@RequestMapping("/sys/logo")
public class SysLogoController {
    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 获取配置
     */
    @ApiOperation(value = "获取配置")
    @GetMapping("/info")
    public R<SysLogoEntity> info(){
        SysLogoEntity logo = sysConfigService.getConfigObject(ConfigConstant.LOGO_CONFIG_KEY, SysLogoEntity.class);

        return R.ok(logo);
    }

    /**
     * 保存配置
     */
    @ApiOperation(value = "保存配置")
    @PostMapping("/save")
    public R save(@RequestBody SysLogoEntity logo){
        //校验类型
        ValidatorUtils.validateEntity(logo);

        sysConfigService.updateValueByKey(ConfigConstant.LOGO_CONFIG_KEY, JSONObject.toJSONString(logo));

        return R.ok();
    }

}
